package com.zjuee.gateway.utils;

import com.zjuee.base.model.AuthUser;
import org.apache.shiro.SecurityUtils;

/**
 * 安全管理工具类
 *
 * @author wu liang
 * @since 2020/8/13 9:54
 */
public class SecurityUtil {

    // header中，携带的sessionId 对应的key
    public static final String AUTHORIZATION = "x-access-token";
    // header中，携带自动登录的key
    public static final String REMEMBER_KEY = "x-access-param";
    public static final String REMEMBER_REQUEST_KEY = "REMEMBER_ME_BASE64";

    // session有效期
    public static final Long TOKEN_EXPIRES_HOUR = 4L;

    /**
     * 获取当前用户
     */
    public static AuthUser getOnlineUser(){
        Object principal = SecurityUtils.getSubject().getPrincipal();
        if (principal==null || !(principal instanceof AuthUser)) {
            return null;
        }
        return (AuthUser) principal;
    }



}
